#include "mylineedit.h"
#include <QDebug>
#include <QKeyEvent>
#include <QMouseEvent>

MyLineEdit::MyLineEdit(QWidget *parent):
    QLineEdit (parent)
{

}

void MyLineEdit::keyPressEvent(QKeyEvent *event)
{
    qDebug() << "按键按下事件:" << event << endl;
    if (event->key() == Qt::Key_A) {
        qDebug() << "按下按键A" << endl;
    }
    qDebug() << "字母:" << event->text() << endl;
    QLineEdit::keyPressEvent(event);
    event->ignore();
}

void MyLineEdit::keyReleaseEvent(QKeyEvent *event)
{
    qDebug() << "按键松开事件:" << event << endl;
    QLineEdit::keyReleaseEvent(event);
    event->ignore();
}

void MyLineEdit::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton) {
        qDebug() << "鼠标左键按下" << endl;
    } else if (event->button() == Qt::RightButton) {
        qDebug() << "鼠标右键按下" << endl;
    } else if (event->button() == Qt::MidButton) {
        qDebug() << "鼠标中间按下" << endl;
    }
}

void MyLineEdit::mouseReleaseEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton) {
        qDebug() << "鼠标左键松开" << endl;
    } else if (event->button() == Qt::RightButton) {
        qDebug() << "鼠标右键松开" << endl;
    } else if (event->button() == Qt::MidButton) {
        qDebug() << "鼠标中间松开" << endl;
    }
}

void MyLineEdit::mouseDoubleClickEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton) {
        qDebug() << "鼠标左键双击" << endl;
    } else if (event->button() == Qt::RightButton) {
        qDebug() << "鼠标右键双击" << endl;
    } else if (event->button() == Qt::MidButton) {
        qDebug() << "鼠标中间双击" << endl;
    }
}

void MyLineEdit::mouseMoveEvent(QMouseEvent *event)
{
    qDebug() << "鼠标移动[" << event->x() << ", " << event->y() << "]" << endl;
    if (event->buttons() & Qt::LeftButton) {
        qDebug() << "鼠标按下左键并移动，" << "鼠标拖动" << endl;
    }
}

bool MyLineEdit::event(QEvent *event)
{
    if (event->type() == QEvent::KeyPress) {
        qDebug() << "QEvent::KeyPress event";
    }
    return QLineEdit::event(event);
}
